package com.gjzt.business.media.service;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.eastdigit.system.service.BaseService;
import com.gjzt.business.media.inter.MediaResourceMarksMapper;
import com.gjzt.business.media.model.MediaResourceMarks;

@Service
public class MediaResourceMarksService extends BaseService {
	
	@Autowired
    private MediaResourceMarksMapper mediaResourceMarksMapper;
	
	public JSONArray queryMarksOfResource(String resourceId){
		StringBuffer sql = new StringBuffer(" select t.MARK_ID, t.MARK_NAME from MEDIA_RESOURCE_MARKS m,MEDIA_MARK_TYPE t WHERE m.MARK_ID = t.MARK_ID ");
		sql.append(" and m.RESOURCE_ID = '").append(resourceId).append("'");
		sql.append(" order by t.PARENT_ID ");
		return this.query(sql.toString());
	}
	
	public JSONArray queryMarksOfBus(String busId){
		StringBuffer sql = new StringBuffer(" select t.MARK_ID, t.MARK_NAME from MEDIA_RESOURCE_MARKS m,MEDIA_MARK_TYPE t WHERE m.MARK_ID = t.MARK_ID ");
		sql.append(" and m.BUS_ID = '").append(busId).append("'");
		sql.append(" order by t.PARENT_ID ");
		return this.query(sql.toString());
	}
	
	public JSONArray queryMarksOfStop(String stopId){
		StringBuffer sql = new StringBuffer(" select t.MARK_ID, t.MARK_NAME from MEDIA_RESOURCE_MARKS m,MEDIA_MARK_TYPE t WHERE m.MARK_ID = t.MARK_ID ");
		sql.append(" and m.STOP_ID = '").append(stopId).append("'");
		sql.append(" order by t.PARENT_ID ");
		return this.query(sql.toString());
	}
	
	public JSONArray queryMarksOfLine(String lineId){
		StringBuffer sql = new StringBuffer(" select t.MARK_ID, t.MARK_NAME from MEDIA_RESOURCE_MARKS m,MEDIA_MARK_TYPE t WHERE m.MARK_ID = t.MARK_ID ");
		sql.append(" and m.lINE_ID = '").append(lineId).append("'");
		sql.append(" order by t.PARENT_ID ");
		return this.query(sql.toString());
	}
	
	public void createResourceMark(String markId, String resourceId){
		MediaResourceMarks mark = new MediaResourceMarks();
		mark.setResourceId(resourceId);
		mark.setMarkId(markId);
		mediaResourceMarksMapper.insert(mark);
	}
	
	public void createStopMark(String markId, String stopId){
		MediaResourceMarks mark = new MediaResourceMarks();
		mark.setStopId(stopId);
		mark.setMarkId(markId);
		mediaResourceMarksMapper.insert(mark);
	}
	
	public void createBusMark(String markId, String busId){
		MediaResourceMarks mark = new MediaResourceMarks();
		mark.setBusId(busId);
		mark.setMarkId(markId);
		mediaResourceMarksMapper.insert(mark);
	}
	
	public void createLineMark(String markId, String lineId){
		MediaResourceMarks mark = new MediaResourceMarks();
		mark.setLineId(lineId);
		mark.setMarkId(markId);
		mediaResourceMarksMapper.insert(mark);
	}
    
	public void removeMarksOfResource(String resourceId){
		mediaResourceMarksMapper.deleteByResourceId(resourceId);
	}
    
	public void removeMarksOfBus(String busId){
		mediaResourceMarksMapper.deleteByBusId(busId);
	}
    
	public void removeMarksOfStop(String stopId){
		mediaResourceMarksMapper.deleteByStopId(stopId);
	}
	
	public void removeMarksOfLine(String lineId){
		mediaResourceMarksMapper.deleteByLineId(lineId);
	}
    
	public void removeMarkId(String markId){
		mediaResourceMarksMapper.deleteByMarkId(markId);
	}
}
